#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2021/1/5 21:19
    Desc  :     环境装饰器
--------------------------------------
"""
from functools import wraps

from flask import request

from application import app


def check_env(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        env = request.headers.get('env')
        app.logger.info(f'环境:{env}')
        if env == 'test':
            app.config['CHILDFITURL'] = 'http://test.api.childfit.cn'
            app.config['DATACHILDFITURL'] = 'http://test.api.data.childfit.cn'
        else:
            app.config['CHILDFITURL'] = 'http://api.childfit.cn'
            app.config['DATACHILDFITURL'] = 'http://api.data.childfit.cn'
        return func(*args, **kwargs)
    return wrapper